package com.liujun.spring4.demo.aop.application.i18n.base;

import java.text.MessageFormat;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.ResourceBundle;

/**
 * @author liujun
 * @version 0.0.1
 * @date 2018/09/11
 */
public class ResourceBundleFormat {

  public static void main(String[] args) {
    ResourceBundle usRb =
        ResourceBundle.getBundle(
            "com/liujun/spring4/demo/application/i18n/base/format/resource", Locale.US);
    System.out.println(usRb.getString("greeting.common"));

    ResourceBundle chRb =
        ResourceBundle.getBundle(
            "com/liujun/spring4/demo/application/i18n/base/format/resource", Locale.CHINA);
    System.out.println(chRb.getString("greeting.morning"));

    Object[] param = new Object[] {"kk", new GregorianCalendar().getTime()};
    try {
      String commOut =
          new MessageFormat(usRb.getString("greeting.common"), Locale.US).format(param);
      System.out.println("userb:" + commOut);

      String commzhCh =
          new MessageFormat(chRb.getString("greeting.morning"), Locale.CHINA).format(param);
      System.out.println("outtime:" + commzhCh);

      String commzhChOut3 =
          new MessageFormat(chRb.getString("greeting.arternoon"), Locale.CHINA).format(param);
      System.out.println("outtimechOut3:" + commzhChOut3);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
